<html>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<title>Exercises</title>
<link rel="STYLESHEET" type="text/css" href="images/style.css">
<link rel="STYLESHEET" type="text/css" href="images/docsafari.css">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/team.gif" width="60" height="17" border="0" align="absmiddle"  alt="Team BBL"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href=ch04lev1sec25.html><img src="images/prev.gif" width="60" height="17" border="0" align="absmiddle" alt="Previous Page"></a>
<a href=ch05.html><img src="images/next.gif" width="60" height="17" border="0" align="absmiddle" alt="Next Page"></a>
</div></td></tr></table>
<br><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top"><a name="ch04lev1sec26"></a>
<h3 class="docSection1Title">Exercises</h3>
<P><table border="0" cellspacing="16" cellpadding="0"><TR valign="top"><td align="right" class="docText" width="50"><a name="ch04qa1q1"></a><B><a class="docLink" href="app03lev1sec4.html#app03qa1q14a14">4.1</a></b></TD><TD><p class="docText"><a name="idd1e33751"></a><a name="idd1e33754"></a><a name="idd1e33759"></a><a name="idd1e33764"></a><a name="idd1e33769"></a><a name="idd1e33774"></a><a name="idd1e33777"></a><a name="idd1e33782"></a><a name="idd1e33787"></a><a name="idd1e33792"></a><a name="idd1e33797"></a><a name="idd1e33802"></a><a name="idd1e33807"></a><a name="idd1e33812"></a><a name="idd1e33817"></a><a name="idd1e33822"></a><a name="idd1e33827"></a><a name="idd1e33832"></a><a name="idd1e33837"></a><a name="idd1e33840"></a><a name="idd1e33845"></a><a name="idd1e33850"></a><a name="idd1e33855"></a>Modify the program in <a class="docLink" href="ch04lev1sec3.html#ch04fig03">Figure 4.3</a> to use <tt>stat</tt> instead of <tt>lstat</tt>. What changes if one of the command-line arguments is a symbolic link?</p></TD></TR><TR valign="top"><td align="right" class="docText" width="50"><a name="ch04qa1q2"></a><B><a class="docLink" href="app03lev1sec4.html#app03qa1q15a15">4.2</a></b></td><TD><p class="docText">What happens if the file mode creation mask is set to 777 (octal)? Verify the results using your shell's <tt>umask</tt> command.</P></TD></tr><TR valign="top"><TD align="right" class="docText" width="50"><a name="ch04qa1q3"></a><b><a class="docLink" href="app03lev1sec4.html#app03qa1q16a16">4.3</a></b></TD><TD><p class="docText">Verify that turning off user-read permission for a file that you own denies your access to the file.</p></td></tr><tr valign="top"><TD align="right" class="docText" width="50"><a name="ch04qa1q4"></a><b><a class="docLink" href="app03lev1sec4.html#app03qa1q17a17">4.4</a></b></TD><td><p class="docText">Run the program in <a class="docLink" href="ch04lev1sec8.html#ch04fig09">Figure 4.9</a> <span class="docEmphasis">after</span> creating the files <tt>foo</tt> and <tt>bar</tt>. What happens?</P></td></tr><tr valign="top"><td align="right" class="docText" width="50"><a name="ch04qa1q5"></a><b><a class="docLink" href="app03lev1sec4.html#app03qa1q18a18">4.5</a></b></td><td><p class="docText">In <a class="docLink" href="ch04lev1sec12.html#ch04lev1sec12">Section 4.12</a>, we said that a file size of 0 is valid for a regular file. We also said that the <tt>st_size</tt> field is defined for directories and symbolic links. Should we ever see a file size of 0 for a directory or a symbolic link?</p></td></tr><tr valign="top"><td align="right" class="docText" width="50"><a name="ch04qa1q6"></a><b>4.6</b></td><td><p class="docText">Write a utility like <tt>cp</tt>(1) that copies a file containing holes, without writing the bytes of 0 to the output file.</p></td></TR><TR valign="top"><td align="right" class="docText" width="50"><a name="ch04qa1q7"></a><B><a class="docLink" href="app03lev1sec4.html#app03qa1q19a19">4.7</a></b></TD><TD><p class="docText">Note in output from the <tt>ls</tt> command in <a class="docLink" href="ch04lev1sec12.html#ch04lev1sec12">Section 4.12</a> that the files <tt>core</tt> and <tt>core.copy</tt> have different access permissions. If the <tt>umask</tt> value didn't change between the creation of the two files, explain how the difference could have occurred.</p></TD></TR><TR valign="top"><td align="right" class="docText" width="50"><a name="ch04qa1q8"></a><B><a class="docLink" href="app03lev1sec4.html#app03qa1q20a20">4.8</a></b></td><TD><p class="docText">When running the program in <a class="docLink" href="ch04lev1sec15.html#ch04fig16">Figure 4.16</a>, we check the available disk space with the <tt>df</tt>(1) command. Why didn't we use the <tt>du</tt>(1) command?</P></TD></tr><TR valign="top"><TD align="right" class="docText" width="50"><a name="ch04qa1q9"></a><b><a class="docLink" href="app03lev1sec4.html#app03qa1q21a21">4.9</a></b></TD><TD><p class="docText">In <a class="docLink" href="ch04lev1sec18.html#ch04fig20">Figure 4.20</a>, we show the <tt>unlink</tt> function as modifying the changed-status time of the file itself. How can this happen?</p></td></tr><tr valign="top"><TD align="right" class="docText" width="50"><a name="ch04qa1q10"></a><b><a class="docLink" href="app03lev1sec4.html#app03qa1q22a22">4.10</a></b></TD><td><p class="docText">In <a class="docLink" href="ch04lev1sec21.html#ch04lev1sec21">Section 4.21</a>, how does the system's limit on the number of open files affect the <tt>myftw</tt> function?</P></td></tr><tr valign="top"><td align="right" class="docText" width="50"><a name="ch04qa1q11"></a><b>4.11</b></td><td><p class="docText">In <a class="docLink" href="ch04lev1sec21.html#ch04lev1sec21">Section 4.21</a>, our version of <tt>ftw</tt> never changes its directory. Modify this routine so that each time it encounters a directory, it does a <tt>chdir</tt> to that directory, allowing it to use the filename and not the pathname for each call to <tt>lstat</tt>. When all the entries in a directory have been processed, execute <tt>chdir("..")</tt>. Compare the time used by this version and the version in the text.</p></td></tr><tr valign="top"><td align="right" class="docText" width="50"><a name="ch04qa1q12"></a><b><a class="docLink" href="app03lev1sec4.html#app03qa1q23a23">4.12</a></b></td><td><p class="docText">Each process also has a root directory that is used for resolution of absolute pathnames. This root directory can be changed with the <tt>chroot</tt> function. Look up the description for this function in your manuals. When might this function be useful?</p></td></TR><TR valign="top"><td align="right" class="docText" width="50"><a name="ch04qa1q13"></a><B><a class="docLink" href="app03lev1sec4.html#app03qa1q24a24">4.13</a></b></TD><TD><p class="docText">How can you set only one of the two time values with the <tt>utime</tt> function?</p></TD></TR><TR valign="top"><td align="right" class="docText" width="50"><a name="ch04qa1q14"></a><B><a class="docLink" href="app03lev1sec4.html#app03qa1q25a25">4.14</a></b></td><TD><p class="docText">Some versions of the <tt>finger</tt>(1) command output &quot;New mail received ...&quot; and &quot;unread since ...&quot; where ... are the corresponding times and dates. How can the program determine these two times and dates?</P></TD></tr><TR valign="top"><TD align="right" class="docText" width="50"><a name="ch04qa1q15"></a><b><a class="docLink" href="app03lev1sec4.html#app03qa1q26a26">4.15</a></b></TD><TD><p class="docText">Examine the archive formats by the <tt>cpio</tt>(1) and <tt>tar</tt>(1) commands. (These descriptions are usually found in Section 5 of the <span class="docEmphasis">UNIX Programmer's Manual</span>.) How many of the three possible time values are saved for each file? When a file is restored, what value do you think the access time is set to, and why?</p></td></tr><tr valign="top"><TD align="right" class="docText" width="50"><a name="ch04qa1q16"></a><b><a class="docLink" href="app03lev1sec4.html#app03qa1q27a27">4.16</a></b></TD><td><p class="docText">Does the UNIX System have a fundamental limitation on the depth of a directory tree? To find out, write a program that creates a directory and then changes to that directory, in a loop. Make certain that the length of the absolute pathname of the leaf of this directory is <a name="idd1e34622"></a><a name="idd1e34627"></a><a name="idd1e34632"></a><a name="idd1e34637"></a>greater than your system's <tt>PATH_MAX</tt> limit. Can you call <tt>getcwd</tt> to fetch the directory's pathname? How do the standard UNIX System tools deal with this long pathname? Can you archive the directory using either <tt>tar</tt> or <tt>cpio</tt>?</P></td></tr><tr valign="top"><td align="right" class="docText" width="50"><a name="ch04qa1q17"></a><b><a class="docLink" href="app03lev1sec4.html#app03qa1q28a28">4.17</a></b></td><td><p class="docText">In <a class="docLink" href="ch03lev1sec16.html#ch03lev1sec16">Section 3.16</a>, we described the <tt>/dev/fd</tt> feature. For any user to be able to access these files, their permissions must be <tt>rw-rw-rw-</tt>. Some programs that create an output file delete the file first, in case it already exists, ignoring the return code:</p>

<pre>
      unlink(path);
      if ((fd = creat(path, FILE_MODE)) &lt; 0)
          err_sys(...);
</pre><br>

<p class="docText">What happens if <tt>path</tt> is <tt>/dev/fd/1</tt>?</p>
</td></tr></table></p>

<a href="17021535.html"><img src="images/pixel.gif" alt="" width="1" height="1" border="0"></a><ul></ul></td></tr></table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/team.gif" width="60" height="17" border="0" align="absmiddle"  alt="Team BBL"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href=ch04lev1sec25.html><img src="images/prev.gif" width="60" height="17" border="0" align="absmiddle" alt="Previous Page"></a>
<a href=ch05.html><img src="images/next.gif" width="60" height="17" border="0" align="absmiddle" alt="Next Page"></a>
</div></td></tr></table>
</body></html><br>
<table width="100%" cellspacing="0" cellpadding="0"
style="margin-top: 0pt; border-collapse: collapse;"> 
<tr> <td align="right" style="background-color=white; border-top: 1px solid gray;"> 
<a href="http://www.zipghost.com/" target="_blank" style="font-family: Tahoma, Verdana;
 font-size: 11px; text-decoration: none;">The CHM file was converted to HTM by Trial version of <b>ChmD<!--69-->ecompiler</b>.</a>
</TD>
</TR><tr>
<td align="right" style="background-color=white; "> 
<a href="http://www.etextwizard.com/download/cd/cdsetup.exe" target="_blank" style="font-family: Tahoma, Verdana;
 font-size: 11px; text-decoration: none;">Download <b>ChmDec<!--69-->ompiler</b> at: http://www.zipghost.com</a>
</TD></tr></table>
